package com.sky.controller.admin;

import com.sky.dto.ServiceCategoryDTO;
import com.sky.dto.ServiceCategoryPageQueryDTO;
import com.sky.entity.ServiceCategory;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.ServiceCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * 服务分类管理
 */
@RestController
@RequestMapping("/admin/service-category")
@Api(tags = "服务分类相关接口")
@Slf4j
public class ServiceCategoryController {

    @Autowired
    private ServiceCategoryService serviceCategoryService;

    /**
     * 新增服务分类
     * @param serviceCategoryDTO
     * @return
     */
    @PostMapping
    @ApiOperation("新增服务分类")
    public Result<String> save(@RequestBody ServiceCategoryDTO serviceCategoryDTO){
        log.info("新增服务分类：{}", serviceCategoryDTO);
        serviceCategoryService.save(serviceCategoryDTO);
        return Result.success();
    }

    /**
     * 服务分类分页查询
     * @param serviceCategoryPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("服务分类分页查询")
    public Result<PageResult> page(ServiceCategoryPageQueryDTO serviceCategoryPageQueryDTO){
        log.info("分页查询：{}", serviceCategoryPageQueryDTO);
        PageResult pageResult = serviceCategoryService.pageQuery(serviceCategoryPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 删除服务分类
     * @param id
     * @return
     */
    @DeleteMapping
    @ApiOperation("删除服务分类")
    public Result<String> deleteById(Long id){
        log.info("删除服务分类：{}", id);
        serviceCategoryService.deleteById(id);
        return Result.success();
    }

    /**
     * 修改服务分类
     * @param serviceCategoryDTO
     * @return
     */
    @PutMapping
    @ApiOperation("修改服务分类")
    public Result<String> update(@RequestBody ServiceCategoryDTO serviceCategoryDTO){
        log.info("修改服务分类：{}", serviceCategoryDTO);
        serviceCategoryService.update(serviceCategoryDTO);
        return Result.success();
    }

    /**
     * 启用、禁用服务分类
     * @param status
     * @param id
     * @return
     */
    @PostMapping("/status/{status}")
    @ApiOperation("启用禁用服务分类")
    public Result<String> startOrStop(@PathVariable("status") Integer status, Long id){
        log.info("启用禁用服务分类：{},{}", status, id);
        serviceCategoryService.startOrStop(status,id);
        return Result.success();
    }

    /**
     * 根据类型查询服务分类
     * @param type
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("根据类型查询服务分类")
    public Result<List<ServiceCategory>> list(Integer type){
        log.info("根据类型查询服务分类：{}", type);
        List<ServiceCategory> list = serviceCategoryService.list(type);
        return Result.success(list);
    }
} 